def traverse_directory(directory, parent_folder = nil)
    Dir.foreach(directory) do |item|
      next if item == '.' || item == '..'
  
      path = File.join(directory, item)
      if File.directory?(path)
        traverse_directory(path, item)  # 递归遍历子目录，并传递文件夹名称
      elsif File.extname(path) == '.txt'
        folder_name = parent_folder || File.basename(directory)  # 获取文件夹名称
        puts "Folder: #{folder_name}"
        puts match_phone_number(File.read(path))  # 输出文件内容
        puts "---------------------------"
      end
    end
  end
  
  # 匹配电话号码的正则
  def match_phone_number(str)
    regex = /(?<!\d)\d{11}(?!\d)/
  
    matches = str.scan(regex)
    matches
  end
# 匹配加盟店编号的正则
def match_m_number(str)
  regex = /[a-zA-Z]\d+/
  match_data = str.match(regex)
  if match_data
    puts "匹配到的结果：#{match_data[0]}"
  else
    puts "没有找到匹配的结果"
  end
end
# 指定目录路径
directory_path = './demo'

# 调用函数开始遍历
traverse_directory(directory_path)
